import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/RoutesPath.dart';
import 'package:flutter_app/tabs.dart';
import 'package:flutter_app/view/big_circle_page.dart';
import 'package:flutter_app/view/my_page.dart';
import 'package:flutter_app/view/topc_detail_page.dart';

//配置路由
final routes = {
  '/': (context) => Tabs(),
  RoutesPath.topicDetail: (context, {arguments}) =>
      TopicDetailPage(id: arguments),
  RoutesPath.myPage: (context) => MyPage(),
  RoutesPath.bigCircle: (context) => BigCirclePage(),
};

//固定写法
// ignore: top_level_function_literal_block
var onGenerateRoute = (RouteSettings settings) {
  //统一处理

  final String name = settings.name;
  final Function pageContentBuilder = routes[name];

  // ignore: top_level_function_literal_block
  if (pageContentBuilder != null) {
    // ignore: top_level_function_literal_block
    if (settings.arguments != null) {
      // ignore: top_level_function_literal_block
      final Route route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));

      return route;
    } else {
      final Route route = MaterialPageRoute(
          builder: (context) =>
              // ignore: missing_return
              pageContentBuilder(context));

      return route;
    }
  } else {
    return null;
  }
};
